package com.test.rest;

import com.sun.jersey.spi.container.servlet.ServletContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

@Path("/hello")
public class JettyServerTest01 {

    @GET
    @Produces("text/plain")
    public String getClichedMessage() {
        return "Hello";
    }

    @GET
    @Path("{name}")
    @Produces("application/json")
    public  Student getStudent(@PathParam("name") String temp) {
        Student student = new Student();
        student.setId(1);
        student.setName(temp);

        return student;
    }

    public static void main(String[] args) throws Exception {

        Server server=new Server(8888);
        ServletHolder servlet = new ServletHolder(ServletContainer.class);
        servlet.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
        servlet.setInitParameter("com.sun.jersey.config.property.packages", "com.test.rest");
        ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        handler.setContextPath("/");
        handler.addServlet(servlet, "/*");
        server.setHandler(handler);
        server.start();
        System.out.println("start...in 8888");

    }
}
